// useMouseEvents.ts
import { ref } from 'vue'
import { DelPushWorks } from '@/api/canvas'
import { ElMessage } from 'element-plus'
import type { TabsPaneContext } from 'element-plus'
export function useMouseEvents() {
  // 示例：定义响应式变量来存储鼠标事件的状态或结果
  const doubleClickCount = ref(0)
  const ListoPen = ref() //抽屉
  const activeName = ref('first') //tabs
  const input = ref('')
  // const HTTP = ref('https://www.baidu.com/')
  const HuiCao = () => {
    if (isValidUrl(input.value)) {
      window.location.href = input.value
      ElMessage({
        message: '跳转网址SUCCESS。。。。。',
        type: 'success'
      })
    } else {
      ElMessage({
        message: '请输入网址。。。。。',
        type: 'error'
      })
    }
  } //回车事件
  // https://www.baidu.com/
  const isValidUrl = (url: string) => {
    return url.startsWith('https://www.baidu.com/') || url.startsWith('https://www.hao123.com/')
  }
  const ShiJiao = () => { } //失焦事件

  // 定义事件处理函数
  const handleDoubleClick = () => {
    doubleClickCount.value++
    console.log(`双击次数: ${doubleClickCount.value}`)
  }

  const handleMouseDown = (event: MouseEvent) => {
    console.log('鼠标按下', event)
  }

  const handleMouseMove = (event: MouseEvent) => {
    console.log('鼠标移动', event.clientX, event.clientY)
  }

  const handleClick = (event: any) => {
    console.log('鼠标单击', event.clientX, event.clientY)
    ListoPen.value = true //打开封装弹框
  }

  const handleMouseWheel = (event: WheelEvent) => {
    console.log('鼠标滚动', event.deltaY)
  }
  const SaoMi = (event: any) => {
    console.log('鼠标滚动', event.clientX, event.clientY)
  }
  //点击画布切换
  const TabhandleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
  }
  //删除我的作品
  // const myworks=ref<Array<any>>([]);
  //   const  DelWork=async(id: any)=>{
  //  if(confirm("确定要删除作品吗？")){
  //     //找id
  //     const index=myworks.value.findIndex((item)=>item.id===id)
  //     if(index !==-1){
  //        myworks.value.splice(index,1)
  //     }

  //     const {data:{code,msg}}=await  DelPushWorks(id)
  //     if(code===0){
  //       ElMessage({
  //         message:msg,
  //         type:'success',
  //         duration:1500

  //       })
  //     }

  //   }

  //   }
  // 返回事件处理函数
  return {
    handleDoubleClick,
    handleMouseDown,
    handleMouseMove,
    handleClick,
    handleMouseWheel,
    SaoMi,
    ListoPen,
    activeName,
    TabhandleClick,
    input,
    HuiCao,
    ShiJiao,
    isValidUrl
    //  DelWork,
    //  myworks
  }
}
